import java.util.Comparator;
import java.util.PriorityQueue;

/*
 *Description:
 *User:laoHu
 *Created with Intellij IDEA 2025
 *Data:2025.09.14
 *Time:12:15
 */
class ImgMaxComparator implements Comparator<Integer>{

    @Override
    public int compare(Integer o1, Integer o2) {
        return o1.compareTo(o2);
    }

}
public class Main{
    public static int[] smallestK(int[] arr, int k) {

        if(k == 0) return new int[0];

        int ret[] = new int[k];

        Heap heap = new Heap();

        for(int i = 0;i < k;i++){
            heap.offer(arr[i]);
        }
        for (int i = k; i < arr.length; i++) {
            if(heap.peek()  > arr[i]){
                heap.poll();
                heap.offer(arr[i]);
            }

        }
        for(int i = 0;i < k;i++){
            ret[i] = heap.poll();
        }
        return ret;
    }

    public static void main(String[] args) {
        ImgMaxComparator imgMaxComparator = new ImgMaxComparator();
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(imgMaxComparator);

        priorityQueue.offer(1);
        priorityQueue.offer(3);

        System.out.println(priorityQueue.peek());
    }

    public static void main2(String[] args) {
        int[] arr = {4,3,2,1};
        int[] ret = smallestK(arr,3);
        for (int i = 0; i < ret.length; i++) {
            System.out.println(ret[i] + " ");
        }

    }
    public static void main1(String[] args) {
        Heap heap = new Heap();
        int[] val = {1,2,3,4,5,6,7};

        heap.initHeap(val);
        heap.creatHeap(heap.ele);

        System.out.println(heap.poll());
        System.out.println(heap.peek());

        PriorityQueue<Integer> queue = new PriorityQueue<Integer>(new Comparator<Integer>() {
            public int compare(Integer num1, Integer num2) {
                return num2 - num1;
            }
        });

    }
}
